<?php

namespace App\Models\Traits;
use Spatie\QueryBuilder\QueryBuilder;
use Spatie\QueryBuilder\AllowedSort;
use Spatie\QueryBuilder\AllowedFilter;
use Spatie\QueryBuilder\AllowedInclude;

trait Query
{
    protected $sort = '-created_at';

    function scopeFilters($query)
    {
        return QueryBuilder::for($query)
            ->defaultSort($this->sort)
            ->allowedSorts($this->allowedSorts())
            ->allowedFields($this->allowedFields())
            ->allowedIncludes($this->allowedIncludes())
            ->allowedFilters($this->allowedFilters());
    }
}